/* XError.cc -- Objeto para reportar erros
 *
 * Copyright (C) 2008, Diogo F. S. Ramos <diogo.ramos@usp.br>
 * GEAR - Grupo de Estudos Avançados em Robótica
 * <http://www.sel.eesc.usp.br/gear>
 *
 * This file is part os GEARMedula.
 * 
 * GEARMedula is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, version 3 of the
 * License.
 * 
 * GEARMedula is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

#include <stdlib.h>
#include <stdio.h>

#include "XError.hh"

#include "config.h"

void
XError::Message( const int exit_status,
		 const char *mode,
		 const char *format,
		 const va_list arg)
{
    fprintf( stderr, "%s:%s:", PACKAGE_NAME, mode);
    vfprintf( stderr, format, arg);
    fprintf( stderr, "\n");
    fflush( stderr );
    
    if( exit_status >= 0 )
    {
	exit(exit_status);
    }

    return;
}

void
XError::Info( const char *format, ... )
{
    va_list arg;

    va_start (arg, format);
    Message( -2, "info", format, arg );
    va_end (arg);
    
    return;
}

void
XError::Warning( const char *format, ... )
{
    va_list arg;

    va_start (arg, format);
    Message( -1, "warning", format, arg );
    va_end (arg);

    return;
}

void
XError::Error( const char *format, ... )
{
    va_list arg;

    va_start (arg, format);
    Message( -1, "error", format, arg );
    va_end (arg);

    return;
}

void
XError::Fatal( const char *format, ... )
{
    va_list arg;

    va_start (arg, format);
    Message( EXIT_FAILURE, "FATAL", format, arg );
    va_end (arg);

    return;
}
